From 2711b46ff73c211f4c9a7d6a863d1dced1eef506 Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Mon, 15 Mar 2021 07:04:10 -0600 Subject: [PATCH] fix Qt6 deprecation warning in mapbar_track. (#703) * fix Qt6 deprecation warning in mapbar_track. "warning: 'fromUtf16' is deprecated: Use char16_t* overload." However, it is recommended to use QString(const QChar *, int) or QString(const QChar *) instead of QString::fromUtf16(const ushort *unicode, int size = -1) and QString::fromUtf16(const char16_t *str, int size = -1) anyway. * fix Either the condition 'track==nullptr' is redundant or there is possible null pointer dereference. as this isn't using a non-throwing allocation function memory allocation errors will cause std::bad_alloc to be thrown anyway, we won't return with track == nullptr. * eliminate another non-functional memory check. --- f90g_track.cc | 1 - mapbar_track.cc | 26 +++++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/f90g_track.cc b/f90g_track.cc index 1ea72c7a4..a949f4713 100644 --- a/f90g_track.cc +++ b/f90g_track.cc @@ -69,7 +69,6 @@ f90g_track_rd_init(const QString& fname) } // start the track list track = new route_head; - is_fatal((track == nullptr), MYNAME ": memory non-enough"); track->rte_name = QFileInfo(fname).fileName(); track_add_head(track); } diff --git a/mapbar_track.cc b/mapbar_track.cc index 25c64aa65..3efc4fd88 100644 --- a/mapbar_track.cc +++ b/mapbar_track.cc @@ -21,8 +21,18 @@ */ +#include // for SEEK_CUR + +#include // for QChar +#include // for QDate +#include // for QString +#include // for QTime +#include // for QVector + #include "defs.h" -#include +#include "gbfile.h" // for gbfgetint16, gbfgetint32, gbfseek, gbfclose, gbfopen, gbfile +#include "src/core/datetime.h" // for DateTime + #define MYNAME "mapbar_track" @@ -58,7 +68,6 @@ read_datetime() int mon = gbfgetint16(fin); int mday = gbfgetint16(fin); gpsbabel::DateTime t(QDate(year, mon, mday), QTime(hour, min, sec)); -// qDebug() << t; return t; } @@ -81,22 +90,21 @@ static void mapbar_track_read() { auto* track = new route_head; - is_fatal((track == nullptr), MYNAME ": memory non-enough"); track_add_head(track); (void) read_datetime(); // start_time currently unused (void) read_datetime(); // end_time currently unused - ushort name[101]; + QChar name[101]; // read 100 UCS-2 characters that are each stored little endian. // note gbfread wouldn't get this right on big endian machines. for (int idx=0; idx<100; idx++) { name[idx] = gbfgetint16(fin); } - name[100] = 0; + name[100] = u'\0'; // At this point, name is a UCS-2 encoded, zero terminated string. // All our internals use Qt encoding, so convert now. - track->rte_name = QString::fromUtf16(name); + track->rte_name = QString(name); // skip two pair waypoint gbfseek(fin, 8*4, SEEK_CUR); @@ -106,11 +114,7 @@ mapbar_track_read() gbfseek(fin, 4, SEEK_CUR); int end_flag = gbfgetint32(fin); - for (;;) { - if (end_flag) { - break; - } - + while (!end_flag) { int length = gbfgetint32(fin); is_fatal((length < 1) || (length > 1600), MYNAME ": get bad buffer length"); -- 2.30.2